﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IE设置
{
    public class Cfglog4
    {
        public static void Cfg()
        {
            //LevelRangeFilter
            log4net.Filter.LevelRangeFilter levfilter = new log4net.Filter.LevelRangeFilter
            {
                LevelMax = log4net.Core.Level.Fatal,
                LevelMin = log4net.Core.Level.Error
            };
            levfilter.ActivateOptions();
            //Appender1
            log4net.Appender.FileAppender appender1 = new log4net.Appender.FileAppender
            {
                AppendToFile = true,
                File = "ErrLog.log",
                ImmediateFlush = true,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                Name = "ErrAppender"
            };
            appender1.AddFilter(levfilter);

            //Appender2
            log4net.Appender.FileAppender appender2 = new log4net.Appender.FileAppender
            {
                AppendToFile = true,
                File = "AllLog.log",
                ImmediateFlush = true,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock()
            };
            appender1.Name = "AllAppender";
            //layout
            log4net.Layout.PatternLayout layout =
                new log4net.Layout.PatternLayout(
                    "%newline文件名称：[ %file ]%newline异常方法：[ %method ]%newline异常行号：[ %line行 ]%newline记录时间：[ %date ]%newline日志级别：[ %-5level ]%newline出 错 类：[ %logger ]%newline属　　性：[ %property{NDC} ]%newline错误描述：[ %message ]%newline");
//            {
//                Header = "------ New session ------" + Environment.NewLine,
//                Footer = "------ End session ------" + Environment.NewLine
//            };
            //Activate
            appender1.Layout = layout;
//            appender2.Layout = layout;
            appender1.ActivateOptions();
//            appender2.ActivateOptions();
            //
            log4net.Config.BasicConfigurator.Configure(appender1);
//            log4net.Config.BasicConfigurator.Configure(appender2);

            //log4net.Repository.ILoggerRepository repository = log4net.LogManager.CreateRepository("MyRepository");
            //log4net.Config.BasicConfigurator.Configure(repository, appender1);
            //log4net.Config.BasicConfigurator.Configure(repository, appender2);
        }
    }
}
